package se.rkrantz.simpleraid.hibernate.domain;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;


@Entity
@Table(name = "WOW_CHARACTER")
public class WowCharacter implements Comparable<WowCharacter> {
	
	public enum Class {Warrior, Rouge, Hunter, Shaman, Paladin, DeathKnight, Priest, Druid, Warlock, Mage};
	
	private long characterId;
	private String characterName;
	private Class characterClass;
	private User user;
	
	private Set<Signup> signups;
	
	@Id
	@GeneratedValue
	@Column(name = "CHARACTER_ID")
	public long getCharacterId() {
		return characterId;
	}
	
	public void setCharacterId(long characterId) {
		this.characterId = characterId;
	}

	@Column(name = "CHARACTER_NAME", nullable = false)
	public String getCharacterName() {
		return characterName;
	}

	public void setCharacterName(String characterName) {
		this.characterName = characterName;
	}

	@Column(name = "CHARACTER_CLASS", nullable = false)
	@Enumerated(EnumType.STRING)
	public Class getCharacterClass() {
		return characterClass;
	}

	public void setCharacterClass(Class characterClass) {
		this.characterClass = characterClass;
	}
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "WOW_CHARACTER_SIGNUP", joinColumns = { @JoinColumn(name = "CHARACTER_ID")}, inverseJoinColumns = { @JoinColumn(name = "SIGNUP_ID")})
	public Set<Signup> getSignups() {
		return signups;
	}
	
	public void setSignups(Set<Signup> signups) {
		this.signups = signups;
	}
	
	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "CHARACTER_USER", inverseJoinColumns = { @JoinColumn(name = "USERNAME")}, joinColumns = { @JoinColumn(name = "CHARACTER_ID")})
	public User getUser() {
		return this.user;
	}
	
	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public int compareTo(WowCharacter other) {
		return this.characterName.compareToIgnoreCase(other.characterName);
	}

}
